package de.bomberman.world;

import com.jme3.asset.AssetManager;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.texture.Texture;
import java.util.logging.Logger;

/**
 *
 * @author Mats
 */
public class Floor {

    private Geometry floorGeom;
    private RigidBodyControl physics;
    // Logger
    private static final Logger logger = Logger.getLogger(Floor.class.getName());

    public Floor(AssetManager assetManager, float floorSize, float floorHeight) {
        Vector3f location = new Vector3f(floorSize, 0, floorSize);

        Box floorBox = new Box(Vector3f.ZERO, floorSize, floorHeight, floorSize);
        floorGeom = new Geometry("floorGeom", floorBox);

        Material floorMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        floorMaterial.setFloat("Shininess", 0); // no specular
        floorMaterial.setColor("Ambient", ColorRGBA.Black);
        floorMaterial.setColor("Diffuse", ColorRGBA.White);
        floorMaterial.setColor("Specular", ColorRGBA.White);

        Texture floorTexture = assetManager.loadTexture("Textures/grass.jpg");
        floorTexture.setWrap(Texture.WrapMode.Repeat);

        floorMaterial.setTexture("LightMap", floorTexture);
        floorBox.scaleTextureCoordinates(new Vector2f(5, 5));

        floorGeom.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
        floorGeom.setMaterial(floorMaterial);

        // setup the physics
        physics = new RigidBodyControl(0.0f);
        floorGeom.addControl(physics);
        physics.setPhysicsLocation(location);
    }

    public Geometry getFloorGeom() {
        return floorGeom;
    }

    public RigidBodyControl getPhysics() {
        return physics;
    }
}
